#include <iostream>
#include <cstdio>
#include <vector>

const int N = 2e6 + 5;

int n;
int sa[N], rk[N], rad[N];
std::vector<int> adj[N], bdj[N];
int bel[N], mx[N];
char s[N];
bool vis[N], ban[N];

inline void dfs(int u, int x) {
	bel[u] = x;
	mx[x] = std::max(mx[x], rk[u]);
	for(int v : adj[u]) if(!bel[v]) bel[u] = x;
}

void solve() {
	std::cin >> n;
	for(int i = 1; i <= n; ++i) rk[i] = 0;
	for(int i = 1; i <= n; ++i) std::cin >> sa[i], ++sa[i];
	for(int i = 1; i <= 2 * n - 1; ++i) std::cin >> rad[i];
   	for(int i = 1; i <= n; ++i) if(sa[i] > n || rad[i] > n) {
		std::cout << -1 << "\n";
		return;
	}
	for(int i = 1; i <= n; ++i) rk[sa[i]] = i;
	for(int i = 1; i <= n; ++i) if(!rk[i]) {
		std::cout << -1 << "\n";
		return;
	}
	for(int i = 1; i <= 2 * n - 1; ++i) {
		if(rad[i] % 2 != i % 2) {
			std::cout << -1 << "\n";
			return;
		}
		++rad[i];
	}
	for(int i = 1; i <= 2 * n - 1; ++i) adj[i].clear(), bdj[i].clear();
	{
	int mx = 0, p = -1;
	for(int i = 1; i <= 2 * n - 1; ++i) {
		int r = i <= mx ? std::min(mx - i + 1, rad[2 * p - i]) : 0;
		if(rad[i] < r) {
			std::cout << -1 << "\n";
			return;
		}
		while(r < rad[i]) {
			int x = i - r, y = i + r;
			if(x % 2 == 1) {
				x = (x + 1) / 2;
				y = (y + 1) / 2;
				if(x != y) {
					//std::cerr << x << " = " << y << "\n";
					adj[x].push_back(y);
					adj[y].push_back(x);
				}
			}
			++r;
		}
		if(i - r > 0 && i + r < 2 * n) {
			int x = i - r, y = i + r;
			if(x % 2 == 1) {
				x = (x + 1) / 2;
				y = (y + 1) / 2;
				//std::cerr << x << " != " << y << "\n";
				bdj[x].push_back(y);
				bdj[y].push_back(x);
			}
		}
		if(i + r - 1 > mx) mx = i + r - 1, p = i;
	}
	}
	for(int i = 1; i <= n; ++i) bel[i] = mx[i] = vis[i] = ban[i] = 0;
	for(int i = 1; i <= n; ++i) {
		if(!bel[i]) {
			dfs(i, i);
		}
	}
	for(int i = 1; i <= n; ++i) for(int j : bdj[i]) if(bel[i] == bel[j]) {
		std::cout << -1 << "\n";
		return;
	}
	//std::cerr << "ok" << "\n";
	int c = 0;
	int p = 1;
	while(p <= n && c < 26) {
		//std::cerr << "c = " << c << " " << p << "\n";
		int last = -1;
		bool okk = 0;
		std::vector<int> bels;
		while(p <= n) {
			//std::cerr << "try p = " << p << "\n";
			int last0 = last;
			int curmax = p;
			int p0 = p;
			bool ok = 1;
			while(p <= curmax) {
				//insert p
				curmax = std::max(curmax, mx[bel[sa[p]]]);
				int u = bel[sa[p]];
				if(!vis[u]) {
					bels.push_back(u);
					if(ban[u]) {
						ok = 0;
						break;
					}
					vis[u] = 1;
					for(int v : bdj[u]) ban[v] = 1;
				}
				if(rk[sa[p] + 1] > last0) {
					last0 = rk[sa[p] + 1];
				} else {
					ok = 0;
					break;
				}
				++p;
			}
			//std::cerr << ok << "\n";
			if(ok) {
				okk = 1;
				last = last0;
				for(int i = p0; i < p; ++i) s[sa[i]] = 'a' + c;
			} else {
				p = p0;
				break;
			}
		}
		for(int u : bels) {
			vis[u] = 0;
			for(int v : bdj[u]) ban[v] = 0;
		}
		if(!okk) {
			std::cout << -1 << "\n";
			return;
		}
		++c;
	}
	for(int i = 1; i <= n; ++i) std::cout << s[i]; std::cout << "\n";
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	std::cout.tie(nullptr);

	std::freopen("string.in", "r", stdin);
	std::freopen("string.out", "w", stdout);

	int t; std::cin >> t;
	while(t--) solve();

	return 0;
}
